/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2022 All Rights Reserved.
 */
package com.yuanmeng.common.rabbitmq.configure;

import java.util.HashMap;
import java.util.Map;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.yuanmeng.common.core.constant.RabbitmqConstants;

/**
 * 短视频延迟队列
 * @author outsider
 * @version Id: DelayQueueDirectConfig.java, v 0.1 2022/11/23 18:04 outsider Exp $$
 */
@Configuration
public class VideoDelayQueueDirectConfig {

    /**
     * 声明短视频死信模式交换机
     *
     */
    @Bean("videoDelayedExchange")
    public CustomExchange delayedExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        /**
         * 1.交换机
         * 2.类型
         * 3.是否持久化
         * 4.是否自动删除
         * 5其他参数
         */
        return new CustomExchange(RabbitmqConstants.VIDEO_DELAYED_EXCHANGE, "x-delayed-message",
            true, false, map);
    }

    /**
     * 交换机
     * @return
     */
    @Bean("videoDelayedQueue")
    public Queue delayedQueue() {
        return new Queue(RabbitmqConstants.VIDEO_DELAYED_QUEUE);
    }

    /**
     * 绑定
     */
    @Bean
    public Binding queueBindingExchange(@Qualifier("videoDelayedExchange") CustomExchange delayedExchange,
                                        @Qualifier("videoDelayedQueue") Queue delayedQueue) {
        return BindingBuilder.bind(delayedQueue).to(delayedExchange)
            .with(RabbitmqConstants.VIDEO_ROUTING_KEY).noargs();
    }
}